#include <bits/stdc++.h>
using namespace std;

int t,n,m,l,v,p[100005],st[100005],ed[100005];

struct node
{
	int d,v,a;
	double l,r;
}car[100005];

struct idx
{
	int id,cnt1;
};

bool cmp(idx x,idx y)
{
	return x.cnt1 > y.cnt1;
}

int main()
{
	freopen("detect1.in","r",stdin);
	freopen("detect1.out","w",stdout);
	cin >> t;
	while(t--)
	{
		cin >> n >> m >> l >> v;
		for(int i = 1;i <= n;i++)
		{
			cin >> car[i].d >> car[i].v >> car[i].a;
			if(car[i].a == 0)
			{
				if(car[i].v > v)
					car[i].l = car[i].d,car[i].r = l;
				else
					car[i].l = car[i].r = -1;
			}
			else if(car[i].a > 0)
			{
				if(car[i].v > v)
					car[i].l = car[i].d,car[i].r = l;
				else
					car[i].l = car[i].d + (v * v - car[i].v * car[i].v) / (2.0 * car[i].a),car[i].r = l;
			}
			else
			{
				if(car[i].v <= v)
					car[i].l = car[i].r = -1;
				else
					car[i].l = car[i].d,car[i].r = min((v * v - car[i].v * car[i].v) / (2.0 * car[i].a) + car[i].d,(double)l);
			}
		}
		for(int i = 1;i <= m;i++)
			cin >> p[i];
		for(int i = 1;i <= n;i++)
		{
			for(int j = 1;j <= m;j++)
			{
				if(p[j] > car[i].l && !st[i])
					st[i] = j;
				if(p[j] > car[i].r && !ed[i])
					ed[i] = j;
			}
			cout << st[i] << ' ' << ed[i] << endl;
		}
		int ans = 5;
		for(int i = 1;i <= n;i++)
			if(st[i] == -1 || ed[i] == -1 || st[i] > ed[i])
				ans--;
		cout << ans << ' ';
		if(n <= 20)
		{
			int ans2 = 0;
			idx cnt[25];
			set<int>s[25];
			memset(cnt,0,sizeof cnt);
			for(int i = 1;i <= n;i++)
				for(int j = st[i];j <= ed[i];j++)
					cnt[i].cnt1++,s[i].insert(j);
			sort(cnt + 1,cnt + n + 1,cmp);
			for(int i = 1;i <= m;i++)
			{
				bool isok = 1;
				for(int j = 1;j <= n;j++)
				{
					if(s[i].find(cnt[i].id) != s[i].end() && s[i].size() == 1)
					{
						isok = 0;
						break;
					}
				}
				ans2++;
				if(!isok)
					continue;
				for(int i = 1;i <= n;i++)
					s[i].erase(*s[i].find(cnt[i].id));
				cnt[i].cnt1 = 0;
			}
			for(int i = 1;i <= n;i++)
				if(cnt[i].cnt1)
					ans2++;
			cout << n - ans2 << endl;
		}
		else
		{
			if(car[1].a >= 0)
			{
				if(ans)
					cout << n - 1 << endl;
				else
					cout << n << endl;
			}
			else
			{
				if(!ans)
					cout << n << endl;
			}
			continue;
		}
	}
	return 0;
}